import {
  getCourseList,
  allSemesterList
} from '../../request/api'
import utils from '../../utils/socketTask'

Page({

  /**
   * 页面的初始数据
   */
  data: {
    semesterList: [],
    option1: [{
      value: 1,
      text: '第1周'
    }, {
      value: 2,
      text: '第2周'
    }, {
      value: 3,
      text: '第3周'
    }, {
      value: 4,
      text: '第4周'
    }, {
      value: 5,
      text: '第5周'
    }, {
      value: 6,
      text: '第6周'
    }, {
      value: 7,
      text: '第7周'
    }, {
      value: 8,
      text: '第8周'
    }, {
      value: 9,
      text: '第9周'
    }, {
      value: 10,
      text: '第10周'
    }, {
      value: 11,
      text: '第11周'
    }, {
      value: 12,
      text: '第12周'
    }, {
      value: 13,
      text: '第13周'
    }, {
      value: 14,
      text: '第14周'
    }, {
      value: 15,
      text: '第15周'
    }, {
      value: 16,
      text: '第16周'
    }, {
      value: 17,
      text: '第17周'
    }, {
      value: 18,
      text: '第18周'
    }, {
      value: 19,
      text: '第19周'
    }, {
      value: 20,
      text: '第20周'
    }],
    option2: [],
    defaultSemester: '',
    defaultWeek: 1,
    value2: 'a',
    week: '',
    semesterId: '',
    width: wx.getSystemInfoSync().windowWidth,
    height: wx.getSystemInfoSync().windowHeight,
    statusBarHeight: wx.getSystemInfoSync().statusBarHeight,
    time: [
      ['8:20', '9:00'],
      ['9:05', '9:45'],
      ['10:00', '10:40'],
      ['10:45', '11:25'],
      ['11:30', '12:10'],
      ['13:30', '14:10'],
      ['14:15', '14:55'],
      ['15:10', '15:50'],
      ['15:55', '16:35'],
      ['16:40', '17:20'],
      ['18:00', '18:40'],
      ['18:45', '19:25'],
      ['19:40', '20:20'],
      ['20:25', '21:05']
    ],
    weekArr: ['', '周一', '周二', '周三', '周四', '周五', '周六', '周日'],
    classArr: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12],
    colorArrays: ['rgba(112,235,85,0.6)', 'rgba(255,196,80,0.6)', 'rgba(255,155,215,0.6)', 'rgba(134,175,254,0.6)', 'rgba(88,238,164,0.6)', 'rgba(255,161,125,0.6)', 'rgba(28,187,180,0.6)', 'rgba(105,100,173,0.6)',
      'rgba(212,34,69,0.6)', 'rgba(33,130,133,0.6)'
    ],
    timeColor: '#000000',
    showNotWeek: true,
    courseList: []
  },
  chengeWeek(e) {
    this.setData({
      week: e.detail
    })
    this.getCourseListData(this.data.week, this.data.semesterId)
  },
  changeSemester(e) {
    if (this.data.week !== null) {
      this.setData({
        semesterId: e.detail
      })
      this.getCourseListData(this.data.week, this.data.semesterId)
    } 
  },
  getCourseListData(week, semesterId) {
    console.log('传的week', week);
    console.log('传的semesterId', semesterId);
    getCourseList(week, semesterId).then(res => {
      console.log('课程表', res)
      this.setData({
        courseList: res.data
      })
    })
  },
  getAllSemesterList() {
    allSemesterList().then(res => {
      if (res.code == 200) {
        console.log('学期列表', res)
        this.setData({
          semesterList: res.data,
          option2: res.data
        })
        for (let i = 0; i < res.data.length; i++) {
          this.setData({
            ['option2[' + i + '].value']: res.data[i].semesterId,
            ['option2[' + i + '].text']: res.data[i].semesterMessage
          })
        }
        this.setData({
          defaultSemester: res.data.length > 0 ? res.data[0].semesterId : '无数据'
        })
      }
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    // this.getCourseListData()
    this.getAllSemesterList()
    this.getCourseListData()
    utils.socketTask()
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})